package com.woniuxy.commons.util;

import com.woniuxy.commons.entity.TestPaper;
import org.apache.xmlbeans.impl.xb.xsdschema.Public;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: 曾令忠
 * @Description:
 * @Date: 2020/7/17 0017-下午 3:09
 */
public class CommonUtil {
    /**
     * 获取固定格式的当前时间的字符串
     * @return 当前时间的字符串
     */
    public static String getCurrentTime() {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return format.format(new Date());
    }

    /**
     *  判断作业有没有过期
     * @param paper
     * @return
     * @throws ParseException
     */
    public static boolean judgeTaskExpired(TestPaper paper) throws ParseException {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date expiredTime = format.parse(paper.getPaperExpireTime());
        return new Date().after(expiredTime);
    }

    /**
     * 根据科目代号返回科目名字
     * @param subjectIndex 科目代号
     * @return 科目名
     */
    public static String getSubjectName(String subjectIndex){
        switch (subjectIndex){
            case "1":
                return "语文";
            case "2":
                return "数学";
            case "3":
                return "外语";
            case "4":
                return "物理";
            case "5":
                return "化学";
            case "6":
                return "生物";
            case "7":
                return "政治";
            case "8":
                return "历史";
            case "9":
                return "地理";
            case "10":
                return "理综";
            case "11":
                return "文综";
            default:
                return "";
        }
    }
}
